package com.graduation.table.enterprise.controller;

import java.util.Arrays;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.graduation.base.Result;
import com.graduation.table.enterprise.entity.Enterprise;
import com.graduation.table.enterprise.service.IEnterpriseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: 校企
 * @Author: jeecg-boot
 * @Date:   2022-05-18
 * @Version: V1.0
 */
@Slf4j
@Api(tags="校企")
@RestController
@RequestMapping("/enterprise")
public class EnterpriseController  {
	@Resource
	private IEnterpriseService enterpriseService;
	
	/**
	 * 分页列表查询
	 *
	 */
	@ApiOperation(value="校企-分页列表查询", notes="校企-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(Enterprise enterprise,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
		LambdaQueryWrapper<Enterprise> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		Page<Enterprise> page = new Page<>(pageNo, pageSize);
		IPage<Enterprise> pageList = enterpriseService.page(page, lambdaQueryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 * 添加
	 *
	 */
	@ApiOperation(value="校企-添加", notes="校企-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody Enterprise enterprise) {
		enterpriseService.save(enterprise);
		return Result.OK("添加成功！");
	}
	
	/**
	 * 编辑
	 *
	 */
	@ApiOperation(value="校企-编辑", notes="校企-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody Enterprise enterprise) {
		enterpriseService.updateById(enterprise);
		return Result.OK("编辑成功!");
	}
	
	/**
	 * 通过id删除
	 *
	 */
	@ApiOperation(value="校企-通过id删除", notes="校企-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id") String id) {
		enterpriseService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 * 批量删除
	 *
	 */
	@ApiOperation(value="校企-批量删除", notes="校企-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids") String ids) {
		this.enterpriseService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功！");
	}
	
	/**
	 * 通过id查询
	 *
	 */
	@ApiOperation(value="校企-通过id查询", notes="校企-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id") String id) {
		Enterprise enterprise = enterpriseService.getById(id);
		return Result.OK(enterprise);
	}

}
